package com.jack.helloworld.activity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import com.jack.helloworld.R;
import com.jack.helloworld.activity.mode.BaseActivity;
import com.jack.helloworld.activity.mode.FirstActivity;
import com.jack.helloworld.fragment.lifecycle.FragmentActivity;
import com.jack.helloworld.receiver.BaseReceiver;
import com.jack.helloworld.util.Constants;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

public class Main05Activity extends BaseActivity {

    private LocalBroadcastManager mLocalBroadcastManager;
    private BaseReceiver mBaseReceiver;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main05);

        mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
        mBaseReceiver = new BaseReceiver();

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Constants.LOCAL_BROADCAST);

        mLocalBroadcastManager.registerReceiver(mBaseReceiver, intentFilter);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLocalBroadcastManager.unregisterReceiver(mBaseReceiver);
    }

    public void doClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.btn_android_processes :
                intent = new Intent(this, AndroidProcessesActivity.class);
                startActivity(intent);
                break;

            case R.id.btn_first_activity :
                intent = new Intent(this, FirstActivity.class);
                startActivity(intent);
                break;

            case R.id.btn_fragment_activity:
                intent = new Intent(this, FragmentActivity.class);
                startActivity(intent);
                break;

            case R.id.btn_send_mybroadcast:
                intent = new Intent(Constants.MY_BROADCAST);
                sendBroadcast(intent);
                break;

            case R.id.btn_send_local_broadcast:
                intent = new Intent(Constants.LOCAL_BROADCAST);
                mLocalBroadcastManager.sendBroadcast(intent);
                break;

            case R.id.btn_login_activity:
                intent = new Intent(this, LoginActivity.class);
                startActivity(intent);
                break;
        }
    }
}
